/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.myapp.struts.actionform;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author pavan
 */
public class AccountHeadFormBean extends org.apache.struts.action.ActionForm {
    
    private String accountHeadNumber,accountHeadName,accountHeadType,schedule,description,balanceType;
    private double openingBalance;

    public String getAccountHeadName() {
        return accountHeadName;
    }

    public void setAccountHeadName(String accountHeadName) {
        this.accountHeadName = accountHeadName;
    }

    public String getAccountHeadNumber() {
        return accountHeadNumber;
    }

    public void setAccountHeadNumber(String accountHeadNumber) {
        this.accountHeadNumber = accountHeadNumber;
    }

    public String getAccountHeadType() {
        return accountHeadType;
    }

    public void setAccountHeadType(String accountHeadType) {
        this.accountHeadType = accountHeadType;
    }

    public String getBalanceType() {
        return balanceType;
    }

    public void setBalanceType(String balanceType) {
        this.balanceType = balanceType;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public double getOpeningBalance() {
        return openingBalance;
    }

    public void setOpeningBalance(double openingBalance) {
        this.openingBalance = openingBalance;
    }

    public String getSchedule() {
        return schedule;
    }

    public void setSchedule(String schedule) {
        this.schedule = schedule;
    }
    
    /**
     *
     */
    public AccountHeadFormBean() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (getAccountHeadName() == null || getAccountHeadName().length() < 1) {
            errors.add("accountHeadName", new ActionMessage("error.acheadName.required"));
        }
        if (getAccountHeadNumber() == null || getAccountHeadNumber().length() < 1) {
            errors.add("accountHeadNumber", new ActionMessage("error.acheadNumber.required"));
        }
        if (getAccountHeadType() == null || getAccountHeadType().length() < 1) {
            errors.add("accountHeadType", new ActionMessage("error.acheadType.required"));
        }
        if (getBalanceType() == null ||  getBalanceType().length() < 1) {
            errors.add("balanceType", new ActionMessage("error.balanceType.required"));
        }
        if (getDescription() == null || getDescription().length() < 1) {
            errors.add("description", new ActionMessage("error.description.required"));
        }
        if (getOpeningBalance() < 0 ) {
            errors.add("openingBalance", new ActionMessage("error.openingBalance.required"));
        }
        if (getSchedule() == null ||  getSchedule().length() < 1) {
            errors.add("schedule", new ActionMessage("error.schedule.required"));
        }       
        return errors;
    }
}
